package com.example.mobile2121606109ycg0425;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class StudentRVAdapter extends RecyclerView.Adapter<StudentRVAdapter.ViewHolder> {
    private List<Student> list;

    public StudentRVAdapter(List<Student> list){
        this.list = list;
    }

    static  class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvName,tvAge,tvGrade,tvPhone;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tvItemName);
            tvAge = itemView.findViewById(R.id.tvItemAge);
            tvGrade = itemView.findViewById(R.id.tvItemGrade);
            tvPhone = itemView.findViewById(R.id.tvItemPhone);

        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_student,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Student student = list.get(position);
//        holder.tvName.setText(student.toString());
//        holder.tvAge.setText(student.toString());
//        holder.tvGrade.setText(student.toString());
//        holder.tvPhone.setText(student.toString());

        holder.tvName.setText(student.getName());
        holder.tvAge.setText(String.valueOf(student.getAge()));
        holder.tvGrade.setText(student.getGrade());
        holder.tvPhone.setText(student.getPhone());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
